package io.itit.ecp.admin.provide.action.resp.largescreen;

import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.experimental.Accessors;

import java.io.Serializable;
import java.math.BigDecimal;
import java.math.RoundingMode;


@Data
@Accessors(chain = true)
public class DataOverviewResp implements Serializable {

    @ApiModelProperty("名称")
    private String name;

    @ApiModelProperty("总量")
    private BigDecimal total;

    @ApiModelProperty("单位")
    private String unit;

    @ApiModelProperty("当前时间范围值")
    private BigDecimal value;

    @ApiModelProperty("同比值")
    private BigDecimal preValue;

    @ApiModelProperty("等效植树量")
    private Integer equivalentTreePlanting;

    @ApiModelProperty("是否上升")
    public Boolean getIsUp() {
        return value.compareTo(preValue) > 0;
    }

    @ApiModelProperty("同比率(百分比)")
    public BigDecimal getRate() {
        BigDecimal subValue = value.subtract(preValue);
        if (preValue.doubleValue() == 0.0D) {
            return new BigDecimal("100");
        }
        return subValue.divide(preValue, 2, RoundingMode.HALF_DOWN).multiply(new BigDecimal(("100"))).setScale(2, RoundingMode.HALF_DOWN);
    }
}
